<template>
	<view class="article-list">
		<view v-for="(article, index) in articles" :key="index" class="article-item">
			<text>{{ article.title }}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				articles: []
			}
		},
		onLoad() {
			this.getArticles();
		},
		methods: {
			async getArticles() {
				try {
					const res = await uni.request({
						url: 'http://localhost:8000/articles/',
						method: 'GET'
					});
					console.log(res)
					if (res.statusCode === 200) {
						this.articles = res.data.articles;
					} else {
						uni.showToast({
							title: '获取文章失败',
							icon: 'none'
						});
					}
				} catch (error) {
					uni.showToast({
						title: '网络错误',
						icon: 'none'
					});
				}
			}
		}
	}
</script>

<style>
	.article-list {
		padding: 20rpx;
	}
	.article-item {
		padding: 20rpx;
		border-bottom: 1rpx solid #eee;
	}
</style>